package com.example.tiantian.process;

import com.example.tiantian.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

@SuppressLint("InflateParams")
public class InfoAdapter extends BaseExpandableListAdapter {

    LayoutInflater inflater;
    MyMap<MyMap<String>> map;

    public InfoAdapter(Context context, MyMap<MyMap<String>> map) {
        inflater = LayoutInflater.from(context);
        this.map = map;
    }

    @Override
    public int getGroupCount() {
        return map.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return map.get(groupPosition).size();
    }

    @Override
    public MyMap<String> getGroup(int groupPosition) {
        return map.get(groupPosition);
    }

    @Override
    public String getChild(int groupPosition, int childPosition) {
        return map.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        class Views {
            TextView title;

            public Views(View v) {
                title = (TextView) v.findViewById(R.id.process_info_group);
            }
        }
        Views views = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.hard_info_group, null);
            views = new Views(convertView);
            convertView.setTag(views);
        } else {
            views = (Views) convertView.getTag();
        }
        views.title.setText(map.getKey(groupPosition));
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
            ViewGroup parent) {

        class Views {
            TextView title;
            TextView content;

            public Views(View v) {
                title = (TextView) v.findViewById(R.id.process_info_tittle);
                content = (TextView) v.findViewById(R.id.process_info_content);
            }
        }
        Views views = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.hard_info_item, null);
            views = new Views(convertView);
            convertView.setTag(views);
        } else {
            views = (Views) convertView.getTag();
        }
        views.title.setText(getGroup(groupPosition).getKey(childPosition));
        views.content.setText(getChild(groupPosition, childPosition));
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

}
